import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Register from '@/pages/Register'
import Search from '@/pages/Search'
import Detail from '@/pages/Detail'
import AddCartSucess from '@/pages/AddCartSuccess'
import ShopCart from "@/pages/ShopCart"
import Trade from "@/pages/Trade"
import Pay from "@/pages/Pay"
import PaySuccess from "@/pages/PaySuccess"
import Center from "@/pages/Center"
import GroupBuy from "@/pages/Center/groupOrder"
import MyOrder from "@/pages/Center/myOrder"
export default [
    {
        path: '/center',
        component: Center,
        children: [
            {
                // path: '/center/myorder',
                path: 'myorder',
                component: MyOrder,
            },
            {
                path: 'groupbuy',
                component: GroupBuy,
            },

            {
                path: '',
                redirect: 'myorder'
            }
        ]
    },
    {
        path: '/paysuccess',
        component: PaySuccess,
        /* 只有从支付界面, 才能跳转到支付成功的界面 */
        beforeEnter(to, from, next) {
            if (from.path === '/pay') {
                next()
            } else {
                next('/pay')
            }
        }
    },
    {
        path: '/pay',
        component: Pay,
        meta: {
            show: true
        },

        // 将query参数映射成props传递给路由组件
        props: route => ({ orderId: route.query.orderId }),

        /* 只能从交易界面, 才能跳转到支付界面 */
        beforeEnter(to, from, next) {
            if (from.path === '/trade') {
                next()
            } else {
                next('/trade')
            }
        }
    },
    {
        name: 'trade',
        path: "/trade",
        component: Trade,
        meta: {
            show: true
        }
    },
    {
        name: 'shopcart',
        path: "/shopcart",
        component: ShopCart,
        meta: {
            show: true
        }
    },
    {
        name: 'addcartsucess',
        path: "/addcartsucess",
        component: AddCartSucess,
        meta: {
            show: true
        }
    },
    {
        name: 'home',
        path: "/home",
        component: Home,
        meta: {
            show: true
        }
    },
    {
        name: 'login',
        path: "/login",
        component: Login,
        meta: {
            show: false
        }
    },
    {
        name: 'register',
        path: "/register",
        component: Register,
        meta: {
            show: false
        }
    },
    {
        name: 'search',
        path: "/search/:keyword?",
        component: Search,
        meta: {
            show: true
        }
    },
    {
        path: "*",
        redirect: "/home"
    },
    {
        path: '/detail/:skuid',
        name: 'detail',
        component: Detail,
        meta: {
            show: true
        }
    }
]
